package com.mcp.stdio.ex.cli;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;

@SuppressWarnings("all")
@SpringBootApplication
public class McpClientApplication {

  public static void main(String[] args) {
    SpringApplication.run(McpClientApplication.class, args);
  }

  // 直接硬编码中文问题，避免配置文件编码问题
  private String userInput = "北京的天气如何？";

  @Bean
  public CommandLineRunner predefinedQuestions(
      ChatClient.Builder chatClientBuilder,
      ToolCallbackProvider tools,
      ConfigurableApplicationContext context) {

    return args -> {
      var chatClient = chatClientBuilder.defaultTools(tools).build();

      System.out.println("\n>>> QUESTION: " + userInput);
      System.out.println("\n>>> ASSISTANT: " + chatClient.prompt(userInput).call().content());

      context.close();
    };
  }
}
